package com.globallogic.dailyplanner.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.primefaces.model.ScheduleEvent;

import com.globallogic.dailyplanner.dto.DailyPlan;
import com.globallogic.dailyplanner.dto.User;

public class TodoBeanUtil {
	public static DailyPlan createDailyPlan(User user, Calendar calendar,
			String activity, String estimateDur, String actualDur,
			String comment) {
		DailyPlan dailyPlan = new DailyPlan();
		dailyPlan.setUser(user);
		dailyPlan.setCalendar(calendar);
		dailyPlan.setActivity(activity);
		dailyPlan.setEstimateDuration(estimateDur);
		dailyPlan.setActualDuration(actualDur);
		dailyPlan.setComment(comment);
		return dailyPlan;
	}
	
	public static String getEstimDuration(ScheduleEvent event) {
		Long duration = 0L;
		duration = event.getEndDate().getTime()
				- event.getStartDate().getTime();
		return duration.toString();
	}

	public static String getActualDuration(MyScheduleEvent event) {
		Long duration = 0L;
		if (event.getActualEndDate() != null){
			duration = event.getActualEndDate().getTime()
					- event.getStartDate().getTime();
		}
		
		return duration.toString();
	}
	
	public static Date getActualDate(DailyPlan dailyPlan){
		Date actualDuration = new Date();
		if (dailyPlan.getActualDuration() != null || !dailyPlan.getActualDuration().equals("")){
			actualDuration.setTime(dailyPlan.getCalendar().getTime().getTime()
					+ Long.parseLong(dailyPlan.getActualDuration()));
			return actualDuration;
		} else{
			return TodoBeanUtil.getEndDate(dailyPlan);
		}

		
	}
	
	public static Date getEndDate(DailyPlan dailyPlan) {
		Date estimDuration = new Date();
		estimDuration.setTime(dailyPlan.getCalendar().getTime().getTime()
				+ Long.parseLong(dailyPlan.getEstimateDuration()));

		return estimDuration;
	}
	
	public static Date getTodayMorningDate(){
		Calendar todayMorning = new GregorianCalendar();
		todayMorning.set(Calendar.HOUR_OF_DAY, 0);
		todayMorning.set(Calendar.MINUTE, 0);
		todayMorning.set(Calendar.SECOND, 0);
		todayMorning.set(Calendar.MILLISECOND, 0);
		
		return todayMorning.getTime();
	}
}
